{********************************************************}
{                                                        }
{                 Zeos Database Objects                  }
{             Oracle8 Transaction component              }
{                                                        }
{       Copyright (c) 1999-2001 Sergey Seroukhov         }
{    Copyright (c) 1999-2002 Zeos Development Group      }
{                                                        }
{********************************************************}

unit ZOraSqlTr;

interface

{$R *.dcr}

uses
  {$IFNDEF LINUX}
  Windows, Db,
  {$ELSE}
  DB,
  {$ENDIF}
  SysUtils, Classes, ZDirOraSql, ZOraSqlCon, ZTransact, ZSqlExtra,
  ZLibOraSql, ZToken, ZSqlTypes;

{$IFNDEF LINUX}
  {$INCLUDE ..\Zeos.inc}
{$ELSE}
  {$INCLUDE ../Zeos.inc}
{$ENDIF}

type
  { Transaction Interbase component }
  TZZOraSqlTransact = class(TZZTransact)
  private
    function GetDatabase: TZZOraSqlDatabase;
    procedure SetDatabase(Value: TZZOraSqlDatabase);
    function  GetTransIsolation: TZZOraSqlTransIsolation;
    procedure SetTransIsolation(const Value: TZZOraSqlTransIsolation);
  public
    constructor Create(AOwner: TComponent); override;

//    function ExecSqlParams(Sql: WideString; Params: TVarRecArray;
//      ParamCount: Integer): LongInt; override;
    function ExecFunc(Func: WideString): WideString; override;

    procedure AddMonitor(Monitor: TZZMonitor); override;
    procedure DeleteMonitor(Monitor: TZZMonitor); override;
  published
    property Database: TZZOraSqlDatabase read GetDatabase write SetDatabase;
    property TransIsolation: TZZOraSqlTransIsolation read GetTransIsolation write SetTransIsolation;
  end;

implementation

uses ZDbaseConst, ZDirSql;

{***************** TZZOraSqlTransact implementation *****************}

{ Class constructor }
constructor TZZOraSqlTransact.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FHandle := TDirOraSqlTransact.Create(nil);
  FQuery  := TDirOraSqlQuery.Create(nil, TDirOraSqlTransact(FHandle));
  FDatabaseType := dtOracle;
end;

{ Get transaction type }
function TZZOraSqlTransact.GetTransIsolation: TZZOraSqlTransIsolation;
begin
  Result := TDirOraSqlTransact(FHandle).TransIsolation;
end;

{ Set transaction type }
procedure TZZOraSqlTransact.SetTransIsolation(const Value: TZZOraSqlTransIsolation);
begin
  if Value <> TDirOraSqlTransact(FHandle).TransIsolation then
  begin
    Disconnect;
    TDirOraSqlTransact(FHandle).TransIsolation := Value;
  end;
end;

{ Add monitor into monitor list }
procedure TZZOraSqlTransact.AddMonitor(Monitor: TZZMonitor);
begin
  ZDirOraSql.MonitorList.AddMonitor(Monitor);
end;

{ Delete monitor from monitor list }
procedure TZZOraSqlTransact.DeleteMonitor(Monitor: TZZMonitor);
begin
  ZDirOraSql.MonitorList.DeleteMonitor(Monitor);
end;

{ Get database component }
function TZZOraSqlTransact.ExecFunc(Func: WideString): WideString;
begin
  if Pos('FROM', UpperCase(Func)) <= 0 then
    Func := Func + ' FROM DUAL';
  Result := inherited ExecFunc(Func);
end;

{ Get database component }
function TZZOraSqlTransact.GetDatabase: TZZOraSqlDatabase;
begin
  Result := TZZOraSqlDatabase(FDatabase);
end;

{ Set database component }
procedure TZZOraSqlTransact.SetDatabase(Value: TZZOraSqlDatabase);
begin
  inherited SetDatabase(Value);
end;
(*
{ Execute a query }
function TZZOraSqlTransact.ExecSqlParams(Sql: WideString;
  Params: TVarRecArray; ParamCount: Integer): LongInt;
var
  OldCursor: TCursor;
  Error: string;
begin
  if not FConnected then
    DatabaseError(LoadStr(SNotConnected));

  OldCursor := Screen.Cursor;
  try
    if toHourGlass in FOptions then
      Screen.Cursor := crSqlWait;

    FQuery.Sql := Sql;
    Result := TDirOraSqlQuery(FQuery).ExecuteParams(Params, ParamCount);
    if FQuery.Status <> qsCommandOk then
    begin
      Error := FQuery.Error;
      Recovery(False);
      DatabaseError(Error);
    end else
      DoDataChange(Sql);

    if FAutoCommit then Commit;
  finally
    Screen.Cursor := OldCursor;
  end;
end;
*)

end.
